/*
 * io_buffer.h
 *
 *  Created on: 20.04.2014
 *      Author: ayoubfalah
 */

#ifndef IO_BUFFER_H_
#define IO_BUFFER_H_

struct io_buffer{
	short size;        		/* The length of the buffer 												 */
	short read_ptr;    		/* Starting from this position can the whole content of the buffer read		 */
	short write_ptr;   		/* The position at where new content can be written    						 */
	char *buffer; 	/* The place where the stored data will be located   						 */
};
typedef struct io_buffer io_buffer;

/**
 * Generating a buffer
 * size the length of the buffer
 * char_buffer represent the initial content of the buffer
 */
static void init_buffer(io_buffer *buffer, char *char_buffer, int size);

/**
 * Reads a character from the buffer
 * i the index of the character that should be read from the buffer
 * It returns the decimal representation of the character
 * at position i according to the ASCII table
 */
static int get_char(io_buffer *buffer, unsigned short i);

/**
 * Inserting a character to the buffer
 * c the character that should be inserted to the buffer
 * It returns the index where new Content can be written
 */
static int put_char(io_buffer *buffer, unsigned char c);

/**
 * checks where the given buffer is empty.
 * It returns 1 if the buffer is empty, otherwise 0
 */
static int is_empty(io_buffer *buffer);

/**
 * checks where the given buffer is full.
 * It returns 1 if the buffer is full, otherwise 0
 */
static int is_full(io_buffer *buffer);

#endif /* IO_BUFFER_H_ */
